﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Impresion;
using SIGEB.Modelo.moduloEstadisticas;
using System.Drawing;
using System.Windows.Forms;

namespace SIGEB.Prototipo.Vista.moduloEstadisticas
{
    public class graficoImprimible:DocumentoImprimible
    {
        public graficoImprimible(ChartStyle estiloBarra, DataCollection coleccionDatos, DataSeries seriesDatos, LinkedList<datoEstadistico> datos, Size Size, Panel PlotPanel)
        {
            this.estiloBarra = estiloBarra;
            this.coleccionDatos = coleccionDatos;
            this.seriesDatos = seriesDatos;
            this.datos = datos;
            this.Size = Size;
            this.PlotPanel = PlotPanel;
        }

        public override int GetHeight()
        {
            return this.Size.Height;
        }

        public override int GetWidth()
        {
            return this.Size.Width;
        }

        public override void pintarObjeto(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (datos != null && datos.Count > 0 && !datos.All(item => item.cantidad == 0))
            {
                //Graphics g = e.Graphics;
                //Rectangle r = new Rectangle(new Point(12, 12), new System.Drawing.Size(661, 410));
                //estiloBarra.ChartArea = r;
                //estiloBarra.SetChartArea(g);
                //e.Graphics.TranslateTransform(PlotPanel.Left, PlotPanel.Top);
                //AddData(g);
                //coleccionDatos.AddBars(g, estiloBarra, coleccionDatos.DataSeriesList.Count, seriesDatos.PointList.Count);
                //estiloBarra.PlotPanelStyle(g);

                Graphics g = e.Graphics;

                g.DrawImageUnscaled(SIGEB.Prototipo.Properties.Resources.sigebimg, 40, 20);
                g.DrawString("Reporte Estadístico", SIGEB.Prototipo.Vista.UI.Fuente.obtenerFuente(20F), Brushes.LightSlateGray, 100, 20);
                g.DrawLine(Pens.LightSlateGray, 20, 70, 640, 70);

                e.Graphics.TranslateTransform(0, 80);
                Rectangle r = new Rectangle(new Point(12, 12), new System.Drawing.Size(661, 535));
                estiloBarra.ChartArea = r;
                estiloBarra.SetChartArea(g);
                e.Graphics.TranslateTransform(PlotPanel.Left, PlotPanel.Top);
                AddData(g);
                coleccionDatos.AddBars(g, estiloBarra, coleccionDatos.DataSeriesList.Count, seriesDatos.PointList.Count);
                estiloBarra.PlotPanelStyle(g);
            }
        }

        private void AddData(Graphics g)
        {
            float x, y;
            coleccionDatos.DataSeriesList.Clear();
            seriesDatos = new DataSeries();
            seriesDatos.BarStyle.BorderColor = Color.LightSteelBlue;
            seriesDatos.BarStyle.FillColor = Color.LightSlateGray;
            for (int i = 0; i < datos.Count; i++)
            {
                x = i + 1;
                y = datos.ElementAt<datoEstadistico>(i).cantidad;
                seriesDatos.AddPoint(new PointF(x, y));
            }
            coleccionDatos.Add(seriesDatos);
        }

        private ChartStyle estiloBarra;
        private DataCollection coleccionDatos;
        private DataSeries seriesDatos;
        private LinkedList<datoEstadistico> datos;
        private Size Size;
        private System.Windows.Forms.Panel PlotPanel;
    }
}
